﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;
using kwzx.Data;
using kwzx.Common;
using System.IO;

namespace kwzx
{
    public partial class SPM_fk : Form
    {
        DataSet1TableAdapters.T_USERTableAdapter T_USER = new DataSet1TableAdapters.T_USERTableAdapter();

        DataSet1TableAdapters.K_DeviceIssueTableAdapter k_deviceIssue = new DataSet1TableAdapters.K_DeviceIssueTableAdapter();

        DataSet1TableAdapters.T_BMTableAdapter bm = new DataSet1TableAdapters.T_BMTableAdapter();
        DataSet1TableAdapters.T_GROUPTableAdapter group = new DataSet1TableAdapters.T_GROUPTableAdapter();
        DataSet1TableAdapters.V_user_cardTableAdapter user_card = new DataSet1TableAdapters.V_user_cardTableAdapter();
        DataSet1TableAdapters.V_jg_bmTableAdapter vjgbm = new DataSet1TableAdapters.V_jg_bmTableAdapter();
        DataSet1TableAdapters.CD_CardTypeTableAdapter cd_card = new DataSet1TableAdapters.CD_CardTypeTableAdapter();

        DataSet1TableAdapters.K_CardTableAdapter k_card = new DataSet1TableAdapters.K_CardTableAdapter();
        string fkbk = "";
        int k_gs_id = 0;
        public SPM_fk(string fkbk1)
        {
            fkbk = fkbk1;
            InitializeComponent();
        }

        private void fk_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“dataSet1.T_User_sfz”中。您可以根据需要移动或删除它。

            // TODO: 这行代码将数据加载到表“sPM.DataTable1”中。您可以根据需要移动或删除它。


            // TODO: 这行代码将数据加载到表“dataSet1.CD_CardType”中。您可以根据需要移动或删除它。
            this.cD_CardTypeTableAdapter.Fill(this.dataSet1.CD_CardType);
            DataTable group_tb = group.GetDataBy_sjjg(0);
            for (int g = 0; g < group_tb.Rows.Count; g++)
            {
                TreeNode tn = new TreeNode();
                tn = treeView1.Nodes.Add(group_tb.Rows[g]["JGNAME"].ToString());
                tn.Text = group_tb.Rows[g]["jc"].ToString();
                tn.Tag = -1;
                tn.ToolTipText = "jg";
                tn.ImageIndex = 0;
                tn.SelectedImageIndex = 0;
                //  tn.Checked = true;
                //addJGTree(tn.Tag.ToString(), tn);
                addBMTree(group_tb.Rows[g]["GRPUP_ID"].ToString(), "0", tn);
            }
            //外协单位
            TreeNode tn1 = new TreeNode();
            tn1 = treeView1.Nodes.Add("外协单位");
            tn1.Text = "外协单位";
            tn1.Tag = "0";
            tn1.ToolTipText = "jg";
            tn1.ImageIndex = 0;
            tn1.SelectedImageIndex = 0;
            tn1.Checked = true;
            addJGTree(group_tb.Rows[0]["GRPUP_ID"].ToString(), tn1);
            treeView1.Nodes[0].ExpandAll();
            treeView1.SelectedNode = treeView1.Nodes[0].NextVisibleNode;

            // treeView1.ExpandAll();
        }



        //private void FillTView()
        //{
        //    //根
        //    treeView1.BeginUpdate();
        //    treeView1.Nodes.Clear();
        //    TreeNode rootNode = new TreeNode("公司名称");
        //    treeView1.Nodes.Add(rootNode);

        //    string oldDept = "公司名称";
        //    string curDept = "";

        //    TreeNode parentNode = rootNode;
        //    TreeNode childNode;

        //    DataTable dt = vjgbm.GetData();
        //    //DataTable dt = GetDataTable("SELECT 总部门, 分部门 FROM TableName ORDER BY 总部门, 分部门");
        //    for (int j = 0; j < dt.Rows.Count; j++)
        //    {
        //        curDept = dt.Rows[j][0].ToString();
        //        if (curDept != oldDept)
        //        {
        //            parentNode = new TreeNode();
        //            parentNode.Text = curDept;
        //            rootNode.Nodes.Add(parentNode);
        //            oldDept = curDept;
        //        }

        //        childNode = new TreeNode();
        //        childNode.Text = dt.Rows[j][1].ToString();
        //        parentNode.Nodes.Add(childNode);
        //    }
        //    treeView1.EndUpdate();
        //}


        /// <summary>
        /// 递归加载addJGTree列表
        /// </summary>
        /// <param name="fatherid">节点的fatherid</param>
        /// <param name="pnode">该节点</param>
        private void addJGTree(string fatherid, TreeNode pnode)
        {
            DataTable dt = group.GetDataBy_sjjg(int.Parse(fatherid));
            DataView dvTree = new DataView(dt);
            dvTree.RowFilter = "[SJJG] = " + fatherid;
            foreach (DataRowView drv in dvTree)
            {
                TreeNode node = new TreeNode();
                node.ImageIndex = 1;
                node.SelectedImageIndex = 3;
                if (pnode == null)
                {
                    node.Text = drv["jc"].ToString();
                    node.Tag = drv["GRPUP_ID"].ToString();    //作为节点标识符
                    node.ToolTipText = "jg";
                    treeView1.Nodes.Add(node);
                    addJGTree(drv["GRPUP_ID"].ToString(), node);//递归  该节点加载子节点
                }
                else
                {
                    node.Text = drv["jc"].ToString();
                    node.Tag = drv["GRPUP_ID"].ToString();//作为节点标识符
                    node.ToolTipText = "jg";
                    pnode.Nodes.Add(node);
                    addJGTree(drv["GRPUP_ID"].ToString(), node);//递归  该节点加载子节点

                }
            }
        }

        /// <summary>
        /// 递归加载addBMTree列表
        /// </summary>
        /// <param name="fatherid">节点的fatherid</param>
        /// <param name="pnode">该节点</param>
        private void addBMTree(string jgid, string fatherid, TreeNode pnode)
        {
            DataTable dt = bm.GetDataBy_grpup_id(int.Parse(jgid));
            DataView dvTree = new DataView(dt);
            dvTree.RowFilter = "[SJBM] = " + fatherid;
            foreach (DataRowView drv in dvTree)
            {
                TreeNode node = new TreeNode();
                node.ImageIndex = 1;
                node.SelectedImageIndex = 3;
                if (pnode == null)
                {
                    node.Text = drv["BMMC"].ToString();
                    node.Tag = drv["DEPT_ID"].ToString();    //作为节点标识符
                    node.ToolTipText = "bm";
                    treeView1.Nodes.Add(node);
                    addBMTree(jgid, drv["DEPT_ID"].ToString(), node);//递归  该节点加载子节点
                }
                else
                {
                    node.Text = drv["BMMC"].ToString();
                    node.Tag = drv["DEPT_ID"].ToString();//作为节点标识符
                    node.ToolTipText = "bm";
                    pnode.Nodes.Add(node);
                    addBMTree(jgid, drv["DEPT_ID"].ToString(), node);//递归  该节点加载子节点
                }
            }
        }

        /// <summary>
        /// 树选中一结点时，在右侧的GridView中关联显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (treeView1.SelectedNode != null)
            {
                int id = int.Parse(e.Node.Tag.ToString());
                string tooltiptext = e.Node.ToolTipText;

                if (tooltiptext.Equals("jg"))
                {
                    this.user_cardTableAdapter.FillBy_Allchild(this.dataSet1.V_user_card, int.Parse(treeView1.SelectedNode.Tag.ToString()));
                }
                else if (tooltiptext.Equals("bm"))
                {
                    this.user_cardTableAdapter.FillBy_DEPT_id(this.dataSet1.V_user_card, int.Parse(treeView1.SelectedNode.Tag.ToString()));
                }
            }
            // button4_Click(sender, e);
            string sql = " 1=1 ";

            if (this.radioButton1.Checked == true)
            {
                sql += "and CardId is NULL";
            }
            else
            {
                sql += "and CardId is not NULL";
            }

            user_crdBindingSource.Filter = sql;
            if (user_crdBindingSource.Count < 1)
            {
                pictureBox1.Image = global::kwzx.Properties.Resources.无图片;
            }
           // user_cardBindingSource_PositionChanged(sender, e);

        }

        /// <summary>
        /// 读取卡号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {

        }
        public static string UrlEncode(string str)
        {
            StringBuilder sb = new StringBuilder();
            byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str); //默认是System.Text.Encoding.Default.GetBytes(str)
            for (int i = 0; i < byStr.Length; i++)
            {
                sb.Append(@"%" + Convert.ToString(byStr[i], 16));
            }

            return (sb.ToString());
        }
        /// <summary>
        /// 级联人员表及卡表信息显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void user_cardBindingSource_PositionChanged(object sender, EventArgs e)
        {



            if (user_crdBindingSource.Current != null)
            {


                string users_id9 = ((DataRowView)user_crdBindingSource.Current)["user_id"].ToString();

                string Imgpath = ((DataRowView)user_crdBindingSource.Current)["zp"].ToString();
                string sfzh1 = ((DataRowView)user_crdBindingSource.Current)["sfzh"].ToString();
                this.t_User_sfzTableAdapter.FillBy_UserNum(this.dataSet1.T_User_sfz, sfzh1);
                this.dataTable1TableAdapter.FillBy_sFieldValue1(this.sPM.DataTable1, sfzh1);
                if (!string.IsNullOrWhiteSpace(Imgpath))
                {
                    int x = Imgpath.IndexOf("ftp/") + 4;
                    string userImg = Imgpath.Substring(x, Imgpath.Length - x);   //ftp下载路径
                    // 路径为:DBFZSPersonImg/李瑞明131684197012105231.jpg
                    int userImginfo = userImg.IndexOf("/") + 1;


                   
                    string zpname = users_id9 + ".dat";
                    string kkzp = FileTran.DownloadFile(SPicUtils.path, zpname, userImg);
                    this.pictureBox1.Image = SPicUtils.PicConvert(kkzp);


                    //FileTran.DownloadFile(SPicUtils.path, "", userImg);
                    //string imgname = userImg.Substring(userImginfo, (userImg.Length - userImginfo));
                    //this.pictureBox1.Image = SPicUtils.PicConvert(SPicUtils.path + imgname);

                }
                else
                {
                    pictureBox1.Image = global::kwzx.Properties.Resources.无图片;
                }

                string users_id = ((DataRowView)user_crdBindingSource.Current)["user_id"].ToString();
                string CardID = ((DataRowView)user_crdBindingSource.Current)["CardID"].ToString();

                // TODO: 这行代码将数据加载到表“dataSet1.K_Carddata”中。您可以根据需要移动或删除它。
                this.k_CarddataTableAdapter.FillBy_user_id(this.dataSet1.K_Carddata, Convert.ToInt32(users_id));

                t_USERTableAdapter.FillBy_ID(this.dataSet1.T_USER, int.Parse(users_id));

                if ((CardID == null) || (CardID == ""))
                {
                    k_CardBindingSource.CancelEdit();
                    // k_CardBindingSource.Clear();
                    this.k_CardBindingSource.AddNew();
                    // this.user_idTextBox1.Text = ((DataRowView)user_crdBindingSource.Current)["user_id"].ToString();
                }
                else
                {
                    k_CardTableAdapter.FillBy_CardID(this.dataSet1.K_Card, int.Parse(CardID));
                }


                ////查询卡类型有效时间
                //DataTable dtct = cd_card.GetDataBy_CT_ID(int.Parse(CT_ID));
                //string CT_DefaultUseDate = "";
                //string CT_Pressure = "0";
                //string CT_UseDUD = "";
                //string CT_Mark = "";
                //if (dtct.Rows.Count > 0)
                //{   
                //CT_Pressure = dtct.Rows[0]["CT_Pressure"].ToString();
                //    double k=double.Parse(CT_Pressure);    


                //    CT_UseDUD = dtct.Rows[0]["CT_UseDUD"].ToString();
                //    CT_Mark = dtct.Rows[0]["CT_Mark"].ToString();
                //    CT_DefaultUseDate = dtct.Rows[0]["CT_DefaultUseDate"].ToString();
                //    CT_Pressure = dtct.Rows[0]["CT_Pressure"].ToString();


                //}
                ////日期


                //string fromdate = "";
                //string to_date = "";
                //if (CT_UseDUD == "False")
                //{
                //    fromdate = DateTime.Now.ToString(); ;
                //    to_date = DateTime.Now.AddYears(30).ToString(); ;
                //}
                //else
                //{
                //    fromdate = DateTime.Now.ToString();
                //    if (CT_Mark == "0")//日
                //    {
                //        double zq = double.Parse(CT_DefaultUseDate);
                //        to_date = DateTime.Now.AddDays(zq).ToShortDateString();
                //    }
                //    if (CT_Mark == "1")//周
                //    {
                //        double zq = double.Parse(CT_DefaultUseDate) * 7;
                //        to_date = DateTime.Now.AddDays(zq).ToShortDateString();
                //    }
                //    if (CT_Mark == "2")//月
                //    {
                //        int zq = int.Parse(CT_DefaultUseDate);
                //        to_date = DateTime.Now.AddMonths(zq).ToShortDateString();
                //    }
                //    if (CT_Mark == "3")//年
                //    {
                //        int zq = int.Parse(CT_DefaultUseDate);
                //        to_date = DateTime.Now.AddYears(zq).ToShortDateString();
                //    }

                //}

            }
            else
            {
                t_USERTableAdapter.FillBy_ID(this.dataSet1.T_USER, -1);
                k_CardTableAdapter.FillBy_CardID(this.dataSet1.K_Card, -1);
            }
        }

        /// <summary>
        /// 搜索操作(查询功能)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            string sql = " 1=1 ";
            if (this.textBox1.Text.ToString() != "")
            {
                sql += " and ZSXM='" + this.textBox1.Text.ToString() + "'";
            }
            if (this.textBox2.Text.ToString() != "")
            {
                sql += "and sfzh='" + this.textBox2.Text.ToString() + "'";
            }
            if (this.radioButton1.Checked == true)
            {
                sql += "and CardId is NULL";
            }
            else
            {
                sql += "and CardId is not NULL";
            }
            user_crdBindingSource.Filter = sql;

            user_cardBindingSource_PositionChanged(sender, e);
            this.user_cardDataGridView.Refresh();
            if (user_crdBindingSource.Count < 1)
            {
                pictureBox1.Image = global::kwzx.Properties.Resources.无图片;
            }
        }

        private void radioButton_CheckedChanged(object sender, EventArgs e)
        {
            string sql = " 1=1 ";
            RadioButton rb = sender as RadioButton;
            if (rb.Name == "radioButton1")
            {
                sql += "and CardId is NULL";
                this.fkbutton.Enabled = true;
            }
            else if (rb.Name == "radioButton2")
            {
                sql += "and CardId is not NULL";
                this.fkbutton.Enabled = false;
            }

            user_crdBindingSource.Filter = sql;
            user_cardBindingSource_PositionChanged(sender, e);
            this.user_cardDataGridView.Refresh();
            if (user_crdBindingSource.Count < 1)
            {
                pictureBox1.Image = global::kwzx.Properties.Resources.无图片;
            }
        }
        private void DDSadd()
        {

        }
        private void fkbutton_Click(object sender, EventArgs e)
        {
            SPMTableAdapters.DataTable1TableAdapter dat = new SPMTableAdapters.DataTable1TableAdapter();
            DataSet1TableAdapters.T_USERTableAdapter tuser = new DataSet1TableAdapters.T_USERTableAdapter();

            DataTable dt = tuser.GetData();
            string sfzid = "";
            int k = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string sfz = dt.Rows[i]["sfzh"].ToString();
                DataTable u = tuser.GetDataBy_sfzh(sfz);
                if (u.Rows.Count > 1)
                {
                    k++;
                    sfzid += "'" + sfz + "',";
                }

            }
            sfzid = sfzid.Replace("'无',", "");
            MessageBox.Show(k.ToString());
        }

        private void gbbutton_Click(object sender, EventArgs e)
        {




            //SPMTableAdapters.DataTable1TableAdapter dat = new SPMTableAdapters.DataTable1TableAdapter();
            //DataSet1TableAdapters.T_USERTableAdapter tuser = new DataSet1TableAdapters.T_USERTableAdapter();//10
            //clyktTableAdapters.T_USERTableAdapter cluser = new clyktTableAdapters.T_USERTableAdapter();//.
            //DataTable dt = cluser.GetData();
            //string sfzid = "";
            //int k = 0;
            //for (int i = 0; i < dt.Rows.Count; i++)
            //{
            //    string sfz = dt.Rows[i]["sfzh"].ToString();
            //    if (sfz!="")
            //    {
            //        DataTable u = tuser.GetDataBy_sfzh(sfz);
            //        if (u.Rows.Count < 1)
            //        {
            //            int DEPT_id = 0;

            //            DEPT_id = int.Parse(dt.Rows[i]["DEPT_id"].ToString());
            //         DateTime tjdate =DateTime.Now;  

            //            tuser.InsertQuery(DEPT_id, dt.Rows[i]["xm"].ToString(), dt.Rows[i]["ZSXM"].ToString(), dt.Rows[i]["GLFW"].ToString(), dt.Rows[i]["XB"].ToString(), dt.Rows[i]["DH"].ToString(), dt.Rows[i]["MM"].ToString(), dt.Rows[i]["EMAIL"].ToString(), dt.Rows[i]["DZ"].ToString(), dt.Rows[i]["RYJJ"].ToString(), dt.Rows[i]["ZW"].ToString(), dt.Rows[i]["ZP"].ToString(), dt.Rows[i]["SFTY"].ToString(), dt.Rows[i]["UBY"].ToString(), int.Parse(dt.Rows[i]["RY_ID"].ToString()), dt.Rows[i]["sfzh"].ToString(), dt.Rows[i]["rybh"].ToString(), tjdate, int.Parse(dt.Rows[i]["gz"].ToString()), int.Parse(dt.Rows[i]["zc"].ToString()), dt.Rows[i]["accgrp"].ToString(), dt.Rows[i]["Jmms"].ToString(), dt.Rows[i]["SSZZ"].ToString(), dt.Rows[i]["zgz"].ToString(), dt.Rows[i]["byyx"].ToString(), dt.Rows[i]["xl"].ToString(), dt.Rows[i]["tsgzzjhm"].ToString(), dt.Rows[i]["DH2"].ToString());
            //            k++;
            //            sfzid += "'" + sfz + "',";
            //        }
            //    }
            //}
            //sfzid = sfzid.Replace("'无',", "");
            //MessageBox.Show(k.ToString());
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SPMTableAdapters.DataTable1TableAdapter dat = new SPMTableAdapters.DataTable1TableAdapter();
            DataSet1TableAdapters.T_USERTableAdapter tuser = new DataSet1TableAdapters.T_USERTableAdapter();

            DataTable dt = dat.GetData();
            string sfzid = "";
            int k = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string sfz = dt.Rows[i]["sFieldValue1"].ToString();
                DataTable u = dat.GetDataBy_sFieldValue1(sfz);
                if (u.Rows.Count > 1)
                {
                    k++;
                    sfzid += "'" + sfz + "',";
                }

            }
            sfzid = sfzid.Replace("'无',", "");
            MessageBox.Show(k.ToString());

        }

        private void button3_Click(object sender, EventArgs e)
        {
            SPMTableAdapters.DataTable1TableAdapter dat = new SPMTableAdapters.DataTable1TableAdapter();
            DataSet1TableAdapters.T_USERTableAdapter tuser = new DataSet1TableAdapters.T_USERTableAdapter();

            DataTable dt = tuser.GetData();
            string sfzid = "";
            int k = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                // string  sfz=    dt.Rows[i]["sFieldValue1"].ToString();
                string sfz = dt.Rows[i]["sfzh"].ToString();
                if (sfz != "")
                {
                    if (sfz.Length > 10)
                    {
                        DataTable u = dat.GetDataBy_sFieldValue1(sfz);
                        if (u.Rows.Count < 1)
                        {
                            k++;
                            sfzid += "'" + sfz + "',";
                        }
                    }
                }
            }
            sfzid = sfzid.Replace("'无',", "");
            MessageBox.Show(k.ToString());
        }

        private void khTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void nUserIdnTextBox_TextChanged(object sender, EventArgs e)
        {
            pictureBox2.ImageLocation = sMTextBox.Text + "\\" + nUserIdnTextBox.Text + ".dat";
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            DataSet1TableAdapters.T_USERTableAdapter tuser = new DataSet1TableAdapters.T_USERTableAdapter();//10
            DataTable dt = tuser.GetData();
            string sfzid = "";
            int k = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string id = dt.Rows[i]["user_id"].ToString();
                string sfz = dt.Rows[i]["sfzh"].ToString();
                if (sfz != "")
                {
                    if (sfz.Length > 10)
                    {
                        string fileName = "";
                        string filePath = dt.Rows[i]["zp"].ToString();

                        if (filePath.Contains("DBPersonImg"))
                        {
                            filePath = filePath.Replace("~/admin/ftp/DBPersonImg/", "");
                            fileName = @"D:\2012-12一卡通整理资料\照片\ftp\DBPersonImg\";
                        }
                        else
                        {
                            filePath = filePath.Replace("~/admin/ftp/DBFZSPersonImg/", "");
                            fileName = @"D:\2012-12一卡通整理资料\照片\ftp\DBFZSPersonImg\";

                        }
                        fileName = fileName + filePath;
                        if (System.IO.File.Exists(fileName))
                        {
                            tuser.UpdateQuery_EMAIL("1", int.Parse(id));
                            //  System.IO.File.Delete(fileName);
                        }
                        else
                        {

                            tuser.UpdateQuery_EMAIL("0", int.Parse(id));
                        }
                    }
                }
            }
            sfzid = sfzid.Replace("'无',", "");
            MessageBox.Show(k.ToString());
        }

        private void button5_Click(object sender, EventArgs e)
        {


            DataSet1TableAdapters.T_USERTableAdapter tuser = new DataSet1TableAdapters.T_USERTableAdapter();//10
            DataTable dt = tuser.GetDataBy_EMAIL();
            // DataTable dt = tuser.GetData();
            string sfzid = "";
            int k = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string id = dt.Rows[i]["user_id"].ToString();
                string sfz = dt.Rows[i]["sfzh"].ToString();
                string zpname = dt.Rows[i]["zsxm"].ToString();

                if (sfz != "")
                {
                    if (sfz.Length > 10)
                    {
                        string fileName = "";
                        string filePath = dt.Rows[i]["zp"].ToString();

                        // if (filePath.Contains("DBPersonImg"))
                        {
                            // filePath = filePath.Replace("~/admin/ftp/DBFZSPersonImg/", "");
                            filePath = filePath.Replace("~/admin/ftp/", "");

                        }

                        fileName = @"C:\门禁信息\ftp\";
                        // fileName = @"C:\门禁信息\7-24 照片\";

                        string yy = @"C:\门禁信息\有用\" + filePath;
                        fileName = fileName + filePath;

                        if (System.IO.File.Exists(fileName))
                        {
                            //System.IO.File.Delete(fileName);
                            // System.IO.File.Move(fileName, yy);

                            tuser.UpdateQuery_EMAIL("1", int.Parse(id));

                        }
                        else
                        {
                            if (dt.Rows[i]["zsxm"].ToString().Contains("访客"))
                            {
                                tuser.UpdateQuery_EMAIL("1", int.Parse(id));
                            }
                            else
                            {
                                tuser.UpdateQuery_EMAIL("0", int.Parse(id));
                            }
                        }

                        ////模糊查询
                        //string path = @"C:\门禁信息\提取所有照片\";
                        //string[] filenames = Directory.GetFiles(path);
                        //foreach (string files in filenames)
                        //{
                        //    if (files.Contains(zpname))
                        //    {
                        //        try
                        //        {
                        //              string vv = @"C:\门禁信息\有用\";
                        //            string kj = "";
                        //            kj = files.Replace(path,vv);

                        //            System.IO.File.Move(files, vv);

                        //        }
                        //        catch (Exception ex)
                        //        {


                        //        }

                        //    }
                        //}
                    }
                }
            }




            sfzid = sfzid.Replace("'无',", "");
            MessageBox.Show(k.ToString());

        }

        private void button6_Click(object sender, EventArgs e)
        {
            string tttty = "'652323197508262614','452730198709232916','45033119900524123X','450722198001105397','622421196501255019','452701197110100718','450722197605155331','452824197004145314','440902196712211617','450702198708288718','460032196306092010','460032197409172034','460032196806030019','460007199004130031','460032197409172034','460032196806030019','410728196104240032','220204196302160910','220204196302160910','210211197209095831','370202197811230715','340826198609154037','452123198710067050','450325198610080946','452528197310244571','452802196610123665','452802196610123665','450703198907013019','450702198708288718','220202197008273019','220202197008273019','411323198011065358','410928197112122111','410928196803052138','410928197112122111','410928196803052138','450703199301121239','321088197507118439','41142519870405633X','321088196202073394','321088197311087714','321088197602083158','321088197507118439','41142519870405633X','321088196202073394','321088197311087714','321088197602083158','450703199301121239','620422198510126431','620422198510126431','410728198910162293','410728198910162293','210211197209095831','370202197811230715','340826198609154037','452123198710067050','450325198610080946','452528197310244571','460032196306092010','460007199004130031','410728196104240032','411323198011065358','411024198804253252','411024198804253252','622421196501255019','450722198001105397','45033119900524123x','452701197110100718','450722197605155331','452824197004145314','452730198709232916','440902198302174074','440902198302174074','452428198101131211','452428198101131211','440902196712211617','450702198303144812','450702198303144812','652323197508262614','450703198907013019'";



            SPMTableAdapters.DataTable1TableAdapter SPMdat = new SPMTableAdapters.DataTable1TableAdapter();
            DataSet1TableAdapters.T_USERTableAdapter tuser = new DataSet1TableAdapters.T_USERTableAdapter();
            DataTable dt = SPMdat.GetData();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string sfzh = dt.Rows[i]["sFieldValue1"].ToString();
                if (!tttty.Contains(sfzh))
                {

                    DataTable ydt = tuser.GetDataBy_sfzh(sfzh);
                    if (ydt.Rows.Count == 1)
                    {
                        string XM = dt.Rows[i]["sUserName"].ToString();
                        string zsxm = dt.Rows[i]["sUserName"].ToString();
                        string DH = dt.Rows[i]["sTelNumber"].ToString();
                        string DH2 = dt.Rows[i]["sFieldValue2"].ToString();
                        string XB = dt.Rows[i]["sFieldValue3"].ToString();
                        if (XB == "0")
                        {
                            XB = "女";
                        }
                        if (XB == "1")
                        {
                            XB = "男";
                        }

                        string user_id = ydt.Rows[0]["user_id"].ToString();
                        tuser.UpdateQuery_spm_dh(XM, zsxm, DH, DH2, XB, int.Parse(user_id));
                    }
                }
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            SPMTableAdapters.DataTable1TableAdapter dat = new SPMTableAdapters.DataTable1TableAdapter();

            DataTable dt = dat.GetData();
            string sfzid = "";
            int k = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                // string  sfz=    dt.Rows[i]["sFieldValue1"].ToString();
                string sfz = dt.Rows[i]["sFieldValue1"].ToString();
                if (sfz != "")
                {
                    if (sfz.Length > 10)
                    {
                        DataTable u = dat.GetDataBy_sFieldValue1(sfz);
                        if (u.Rows.Count > 1)
                        {
                            k++;
                            sfzid += "'" + sfz + "',";
                        }
                    }
                }
            }
            sfzid = sfzid.Replace("'无',", "");
            MessageBox.Show(k.ToString());
        }

        private void button8_Click(object sender, EventArgs e)
        {

            DataSet1TableAdapters.T_USERTableAdapter tuser = new DataSet1TableAdapters.T_USERTableAdapter();//10
            DataTable dt = tuser.GetDataBy_EMAIL();
            // DataTable dt = tuser.GetData();
            string sfzid = "";
            int k = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string id = dt.Rows[i]["user_id"].ToString();
                string sfz = dt.Rows[i]["sfzh"].ToString();
                string zpname = dt.Rows[i]["zsxm"].ToString();

                if (sfz != "")
                {
                    if (sfz.Length > 10)
                    {
                        string fileName = "";
                        string filePath = dt.Rows[i]["zp"].ToString();

                        // if (filePath.Contains("DBPersonImg"))
                        {
                            filePath = filePath.Replace("~/admin/ftp/DBFZSPersonImg/", "");


                        }


                        fileName = @"C:\门禁信息\7-24 照片\";

                        string yy = @"C:\门禁信息\有用\" + filePath;
                        fileName = fileName + filePath;



                        //模糊查询
                        string path = @"C:\门禁信息\png7-24\png7-24";
                        string[] filenames = Directory.GetFiles(path);
                        foreach (string files in filenames)
                        {
                            if (files.Contains(sfz))
                            {
                                try
                                {
                                    string vv = @"C:\门禁信息\有用\";
                                    string kj = "";
                                    kj = files.Replace(path, vv);
                                    kj = kj.Replace(".png", ".jpg");
                                    System.IO.File.Move(files,kj);

                                }
                                catch (Exception ex)
                                {


                                }

                            }
                        }
                    }
                }
            }




            sfzid = sfzid.Replace("'无',", "");
            MessageBox.Show(k.ToString());

        }

        private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            DataSet2TableAdapters.M_user_accgrpTableAdapter useracc = new DataSet2TableAdapters.M_user_accgrpTableAdapter();
           

            string ZSXM = ((DataRowView)user_crdBindingSource.Current)["ZSXM"].ToString();
            if (MessageBox.Show("确定要删除 [" + ZSXM + "] 的信息吗?", "提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
            {

                string userid = ((DataRowView)user_crdBindingSource.Current)["user_id"].ToString();
                useracc.deletem_user_id(int.Parse(userid));
            T_USER.DeleteQuery_user_id(int.Parse(userid));
                user_cardDataGridView.Rows.RemoveAt(user_cardDataGridView.CurrentRow.Index);
            }
        }
    }
}











